// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:jd_flutter/base/utils/preview_tool.dart';
import 'package:jd_flutter/base/widget/image/jd_network_image.dart';

class FocusImageDemo extends StatelessWidget {
  const FocusImageDemo({super.key});
  static String routeName = 'misc/focus_image';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Focus Image')),
      body: const Grid(),
    );
  }
}

class Grid extends StatelessWidget {
  const Grid({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GridView.builder(
        itemCount: 8,
        gridDelegate:
            const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
        itemBuilder: (context, index) {
          return SmallCard(imageName: testUrl, index: index);
        },
      ),
    );
  }
}

class SmallCard extends StatelessWidget {
  const SmallCard({required this.imageName, required this.index, super.key});
  final String imageName;
  final int index;
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Material(
        child: InkWell(
          onTap: () {
            List<String> picList = [
              testUrl,
              testUrl,
              testUrl,
              testUrl,
              testUrl,
              testUrl,
              testUrl,
              testUrl,
              testUrl,
            ];
            PreviewTool.showPicList(context, picList, 0);
          },
          child: Hero(
            tag: index,
            child: JDNetworkImage(
              url: imageName,
            ),
          ),
        ),
      ),
    );
  }
}
